package com.baimawangzi.recovery.dao.impl;

import com.baimawangzi.recovery.bean.Transaction;
import com.baimawangzi.recovery.bean.User;
import com.baimawangzi.recovery.dao.TransactionDao;
import com.baimawangzi.recovery.util.dbutil.BeanHandler;
import com.baimawangzi.recovery.util.dbutil.OnlyHandler;

import java.util.List;

public class TransactionDaoImpl extends BaseDaoImpl<Transaction> implements TransactionDao {
    public TransactionDaoImpl() {
        clazz= User.class;
        init();
    }

    @Override
    public List<Transaction> findByLimit(int m, int n) {
        //String sql ="select t.id,t.ordername,u.username username,c.couriername,date_format(t.createtime,'%Y-%m-%d %H:%i:%S') createtime,date_format(t.finishtime,'%Y-%m-%d %H:%i:%S') finishtime from t_transaction t,t_user u,t_courier c";
        String sql ="select t.id,t.ordername,u.username username,c.couriername,date_format(t.createtime,'%Y-%m-%d %H:%i:%S') createtime,date_format(t.finishtime,'%Y-%m-%d %H:%i:%S') finishtime from t_transaction t left join t_courier c on c.id = t.courierid left join t_user u on u.id = t.creareuserid limit ?,?";
        //String sql="select t.id id,t.ordername ordername,u.username creareusername,c.couriername couriername,t.createtime createtime,t.finishtime finishtime from t_transaction t left join t_courier c on c.id = t.courierid left join t_user u on u.id = t.creareuserid ";
        //String sql="select t.id id,t.ordername ordername,c.couriername couriername,t.createtime createtime,t.finishtime finishtime from t_transaction t left join t_courier c on c.id = t.courierid left join t_user u on u.id = t.creareuserid limit ?,?";
        Object[] object= {m, n};
//        Object[] object= {};
        List<Transaction>transactions = queryRunner.query(sql,new BeanHandler<>(Transaction.class),object);
        return transactions;
    }

    @Override
    public long getCount() {
        String sql="select count(*) totalSize from t_transaction where ?=?";

        Object[] objects={1,1};
        List<Object> onlylist = queryRunner.query(sql, new OnlyHandler(), objects);
        return (long) onlylist.get(0);

    }
}
